home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / mail / YAMscripts.lha / ArchiveFolder.rexx < prev    next >
OS/2 REXX Batch file  |  1997-06-24  |  3KB  |  119 lines

  1. /* ArchiveFolder.rexx 1.2 02-Jun-97 by Kai Nikulainen
  2. **
  3. ** Renames messages in a folder to their subjects and moves them into a
  4. ** .lha archive.
  5. **
  6. ** Do not add messages to an older archive, because that could cause
  7. ** clashes with filenames and all messages would not be saved!
  8. **
  9. ** Mail your comments and bug reports to knikulai@utu.fi */
  10.  
  11. options results
  12.  
  13. DeleteAll='yes'    /* If yes, all files left in the folder will be deleted after archiving*/
  14. RemSpaces='no'    /* If yes, spaces are removed.  Otherwise they are translated to _ */
  15. Arc='c:lha a'    /* Use this command to archive the messages */
  16. Defpath='Work:' /* Default path for the file requester */
  17. tags='rt_pubscrname=YAMSCREEN'    /* Change here the name of the screen YAM runs */
  18.  
  19.         /* The following lines define substrings which are removed from the */
  20.         /* filenames.  Substrings are case insensitive! */
  21. dels=2        /* How many undesired substrings are there? */
  22. del.1='Re: '    /* Note that words are removed in the order they are given */
  23. del.2='Re:'    /* So, if 'Re:' would come before 'Re: ' that might leave a space*/
  24.         /* in the beginning of filenames */
  25.  
  26. BadChars='*:/?"'/* These chars will be translated to _ */
  27.  
  28. call addlib('rexxsupport.library',0,-30,0)
  29. call addlib('rexxreqtools.library',0,-30,0)
  30.  
  31. do d=1 to dels
  32.     del.d=upper(del.d)
  33.     end
  34.  
  35. sc=0
  36. address 'YAM'
  37. 'MailUpdate'        /* Let's make sure the index is up to date */
  38. 'GetFolderInfo Max'    /* How many messages are there? */
  39. n=result
  40.  
  41. 'GetFolderInfo Path'    /* Where is the folder */
  42. fp=result
  43. if pos(':',fp)=0 then fp='YAM:'fp
  44. if right(fp,1)~='/' & right(fp,1)~=':' then fp=fp'/'
  45.  
  46. 'GetFolderInfo Name'    /* What's it's name */
  47. arcname=result date()
  48. if upper(RemSpaces)~='YES' then
  49.     arcname=translate(arcname,'_',' ')
  50.  
  51. arcname=compress(arcname,' ' || BadChars)
  52. arcname=rtfilerequest(DefPath,arcname,'Select archive name',,tags)
  53. if arcname='' then exit
  54.  
  55. 'Hide'            /* It's faster to scan all messages while YAM is hidden */
  56. do m=0 to n-1        /* Do for all messages in folder: */
  57.     'SetMail' m        /* Select a message */
  58.     'GetMailInfo File'    /* Get the filename */
  59.     file=result        /* Save the filename */
  60.     'GetMailInfo Subject'    /* Guess what it does now? */
  61.     subj=result
  62.     do d=1 to dels
  63.         p=pos(del.d,upper(subj))
  64.         do while p>0 
  65.             subj=left(subj,p-1) || substr(subj,p+length(del.d))
  66.             p=pos(del.d,upper(subj))
  67.             end
  68.         end
  69.     subj=translate(subj,'_',BadChars)
  70.     if upper(RemSpaces)='YES' then
  71.         subj=Compress(subj)
  72.     else
  73.         subj=Translate(subj,'_',' ')
  74.     if length(subj)>30 then subj=left(subj,30)    /* the name may be shortened */
  75.     if subj='' then subj='No subject'        /* every message needs one...*/
  76.     num=CheckName(subj)                /* find duplicates */
  77.     if length(subj || num)>30 then 
  78.         subj=left(subj,30-length(num)) || num
  79.     else
  80.         subj=subj || num
  81.     address command 'Filenote' file file        /* this might help restoring things*/
  82.     address command 'Rename' file '"'fp || subj'"'
  83.  
  84. end /* do m */
  85.  
  86. /* Let's open a window... */
  87. Call Close(STDOUT)
  88. Call Close(STDIN)
  89.  
  90. Call Open(STDOUT,'CON:1/11/600/180/ArchiveFolder.rexx Output/CLOSE/WAIT/SCREEN'scrn,'w')
  91. Call Pragma('*',STDOUT)
  92.  
  93. address command arc '"'arcname'"' fp
  94. if upper(DeleteAll)='YES' then address command 'delete' fp'#?'
  95.  
  96. Say 'You can close the window now'
  97. 'MailUpdate'
  98. 'Show'
  99. exit
  100.  
  101. CheckName:
  102. parse arg s
  103.     i=1
  104.     s=upper(s)
  105.     do while i<sc & s~=su.i
  106.         i=i+1
  107.         end
  108.     if s=su.i then do
  109.         copies.i=copies.i+1
  110.         c='['copies.i']'
  111.         end
  112.     else do
  113.         sc=sc+1
  114.         su.sc=s
  115.         copies.sc=0
  116.         c=''
  117.         end
  118. return c
  119.